package com.mb.app.appused.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public abstract class BaseFragment extends Fragment {

	public View baseView = null;
	public LayoutInflater inflater;

	public abstract int getViewLayout();

	public abstract void initView();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		baseView = inflater.inflate(getViewLayout(), null);
		this.inflater = inflater;
		return baseView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		initView();
	}
	/**
	 * 获取通用对象
	 * 
	 * @param id
	 * @return
	 */
	protected Object getObject(int id) {
		return getView().findViewById(id);
	}

	public View getBaseView() {
		return baseView;
	}

	public LayoutInflater getInflater() {
		return inflater;
	}
	
	/**
	 * 设置标题
	 * @param id
	 * @param lable
	 */
	public void setTitle(int id, String lable) {
		TextView txt = (TextView) baseView.findViewById(id);
		if (txt == null)
			return;
		if (lable == null) {
			txt.setVisibility(View.GONE);
			return;
		}
		txt.setText(lable);
	}
}
